//
//  XPPXcodeAboutMenuItem.m
//  XPPXcodePlugin
//
//  Created by yoyokko on 10-4-21.
//  Copyright 2010 yoyokko@gmail.com. All rights reserved.
//

#import "XPPXcodePlugin.h"
#import "XPPXcodeMenuItem.h"


// Handles the about GTM Xcode Plugin menu item in the Application menu.
@interface XPPXcodeAboutMenuItem : XPPXcodeMenuItem
@end

@implementation XPPXcodeAboutMenuItem
+ (void)load {
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	[XPPXcodePlugin registerMenuItem:[[[self alloc] init] autorelease]];
	[pool release];
}

- (NSString*)title {
	return @"About XPP Xcode Plugin";
}

- (void)action:(id)sender {
	NSBundle *mainBundle = [XPPXcodePlugin pluginBundle];
	NSString *creditsPath = [mainBundle pathForResource:@"Credits" ofType:@"rtf"];
	NSAttributedString *credits
    = [[[NSAttributedString alloc] initWithPath:creditsPath
                             documentAttributes:nil] autorelease];

	NSString *path = [mainBundle pathForResource:@"XPP"
										  ofType:@"icns"];
	NSImage *icon = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
	NSDictionary *optionsDict = [NSDictionary dictionaryWithObjectsAndKeys:
								 credits, @"Credits",
								 [mainBundle objectForInfoDictionaryKey:@"CFBundleName"],
								 @"ApplicationName",
								 [mainBundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"],
								 @"Copyright",
								 [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
								 @"ApplicationVersion",
								 @"", @"Version",
								 icon, @"ApplicationIcon",
								 nil];
	[NSApp orderFrontStandardAboutPanelWithOptions:optionsDict];
}

- (NSMenu*)insertionMenu {
	NSMenu *rootMenu = [NSApp mainMenu];
	NSMenuItem *appleMenuItem = [rootMenu itemAtIndex:0];
	return [appleMenuItem submenu];
}

- (int)insertionIndex {
	return 1;
}
@end
